
var app = require('./server');
var http = require('http');


var port = process.env.PORT || '3030';
app.set('port', port);

var server = http.createServer(app);
//star 10-8 捕获node 报错，解决报错引起的node退出。
process.on('uncaughtException', function (err) {
  //打印出错误
  console.error('-----------------------err start')
  console.error(err);
  console.error('------------------------err end')
});
server.listen(port, function () {
  console.log('App start in http://127.0.0.1:' + port);
});
server.on('error', onError);
server.on('listening', onListening);
/**
 * Event listener for HTTP server "error" event.
 */

function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }

  var bind = typeof port === 'string'
    ? 'Pipe ' + port
    : 'Port ' + port;

  // handle specific listen errors with friendly messages
  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}
function onListening() {
  var addr = server.address();
  var bind = typeof addr === 'string'
    ? 'pipe ' + addr
    : 'port ' + addr.port;
  console.log('Listening on ' + bind);
}
